package base.多线程.同步代码.消费者和生产者;

public class Producer extends Thread{
    @Override
    public void run() {
        while (true){

            synchronized (Desk.lock){

                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

                if (Desk.count == 0){
                    break;
                }else {
                    if (Desk.foodFlag == 1){
                        try {
                            Desk.lock.wait();
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }else {
                        System.out.println("【老板】:正在下第"+(10-Desk.count+1)+"碗面条~");
                        Desk.foodFlag = 1;
                        Desk.lock.notifyAll();
                    }
                }
            }
        }
    }
}
